package net.lzzy.practices.utils;

import com.alibaba.fastjson.JSONObject;
import net.lzzy.practices.web.models.BaseInfo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

/**
 *@author hzl on 2022/5/18.
 *Description:
 */
public class AspectUtils {
    public static String getToken(ProceedingJoinPoint point){
        Object[] args=point.getArgs();
       String[] names= ((MethodSignature)point.getSignature()).getParameterNames();
       int i=0;
       for (String name:names){
           if ("token".equals(name)) {
               return args[i].toString();
           }
           i++;
       }
       if (args[0] instanceof BaseInfo){
           return ((BaseInfo)args[0]).getToken();
       }else {
           JSONObject obj=(JSONObject) args[0];
           return obj.getString("token");
       }
    }
}
